package com.example.demo.t2;

import java.util.*;
import java.util.function.IntUnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class T2_5 {

    public static Integer add(Integer x, Integer y){
        return x+y;
    }


    public static void main(String[] args) {

        Stream<Integer> str = Stream.of(1,2,3,4,5,6);
        Stream<String> str2 = str.map(o -> o.toString());

        Optional<Integer> xx = Stream.of(1,2,3,4,5,6)
                .map(o -> o.toString())
//                .map(o -> o + o)
//                .map(o -> o + o + o)
                .map(Integer::parseInt)
//                .reduce(0, (x,y) -> x+y);
                .reduce(T2_5::add);

        System.out.println(xx.get());

        Integer xxx = IntStream.of()
//                .map(o -> o.toString())
//                .map(Integer::parseInt)
                .reduce(55, (x,y) -> x + y);

        OptionalInt xxxx = IntStream.of()
                .reduce((x,y) -> x + y);
        System.out.println(xxxx.isPresent() ? xxxx.getAsInt() : 0);

        Integer xxxxx = IntStream.of()
                .reduce((x,y) -> x + y)
                .orElse(-99);
        System.out.println(xxxxx);

        var s1 = Stream.of(1,3,5,3,2,3,4,2);
        s1.sorted().forEach(System.out::println);

//        <U> Stream<U> mapToObj(IntFunction<? extends U> mapper);
//        IntStream map(IntUnaryOperator mapper);

        Set<Character> s = Stream.of("My", "Mine")
            .flatMap(o -> o.chars().mapToObj(oo -> (char)oo))
                .collect(Collectors.toSet());
//                .forEach(System.out::println);
//                .forEach(System.out::println);






    }
}
